package com.example.administrator.testproject.Tag;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.ListView;

/**
 * Created by shengfh on 2017/11/15.
 */

public class MaxHeightListView extends ListView {
    private FrameLayout emptyLayout;

    public MaxHeightListView(Context context) {
        super(context);
        setFocusable(false);
    }

    public MaxHeightListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setFocusable(false);
    }

    public MaxHeightListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setFocusable(false);
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }


//    private void initEmeptyView() {
//        try {
//            ImageView view = new ImageView(getContext());
//            view.setImageResource(R.drawable.bg_empty_list);
//            view.setScaleType(ImageView.ScaleType.FIT_XY);
//            view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
//            setEmptyView(view);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }

//    private View emptyView;
//
//
//    @Override
//    public void setAdapter(ListAdapter adapter) {
//        super.setAdapter(adapter);
//        initEmeptyView();
//    }
//
//    @Override
//    public void setEmptyView(View emptyView) {
//        this.emptyView = emptyView;
////        ((ViewGroup) this.getRootView()).addView(emptyView);
////        super.setEmptyView(emptyView);
//
//        if (getEmptyView() == null) {
//            emptyLayout = new FrameLayout(getContext());
//            emptyLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
//            emptyView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
//            emptyLayout.addView(emptyView);
//            emptyView.setVisibility(View.VISIBLE);
//            ViewGroup parent = (ViewGroup) this.getParent();
////            if (this.getParent() instanceof ScrollView) {
////                emptyLayout.addView(this);
////                parent.removeAllViews();
////            }
//            parent.addView(emptyLayout);
//            super.setEmptyView(emptyLayout);
//        } else {
//            emptyLayout = (FrameLayout) getEmptyView();
//            emptyLayout.removeAllViews();
//            emptyLayout.setVisibility(View.VISIBLE);
//            emptyLayout.addView(emptyView);
//        }
//
//    }
//
//    private static ViewGroup getParentView(ViewGroup parent) {
//        ViewGroup tempVg = parent;
//        if (parent.getParent() != null && parent.getParent() instanceof ViewGroup) {
//            tempVg = (ViewGroup) parent.getParent();
//            getParentView(tempVg);
//        } else {
//            return tempVg;
//        }
//        return tempVg;
//    }

    //    public void setEmptyView(View view) {
//        this.emptyView = view;
//        ((ViewGroup) this.getRootView()).addView(view);
//    }


}
